/* Includes ------------------------------------------------------------------*/
#include "page_start.h"
#include "lvgl/lvgl.h"
#include "main.h"

/* Private macro -------------------------------------------------------------*/

/* Private typedef -----------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/
void timer_callback_main(lv_timer_t *timer);
void set_img_angle_callback(void *obj, int32_t v);

/* Private functions ---------------------------------------------------------*/

/******************************************************************************
 * Function Name  : ui_start
 * Description    : ui start page
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
// static lv_ft_info_t fn_info;
void ui_start(void)
{
    ui_t *ui = &device.ui;
    device.current_page = PAGE_START;

    device.ui.scr = lv_disp_get_scr_act(NULL); /*Get the current screen*/
    lv_obj_set_size(device.ui.scr, LV_HOR_RES_MAX, LV_VER_RES_MAX);

    lv_obj_set_style_bg_color(device.ui.scr, lv_color_black(), 0);
    lv_obj_set_style_bg_opa(device.ui.scr, LV_OPA_COVER, 0);
    lv_obj_set_style_opa(device.ui.scr, LV_OPA_COVER, 0);
    
    device.ui.start.label = lv_label_create(device.ui.scr);
    lv_obj_set_style_text_color(device.ui.start.label, lv_color_hex(0xffffff), 0);
    lv_obj_set_style_text_font(device.ui.start.label, device.ui.fnt.size_20.font, 0);
    lv_label_set_text(device.ui.start.label, "控制系统正在启动...");
    lv_obj_align(device.ui.start.label, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_y(device.ui.start.label, lv_obj_get_y(device.ui.start.label) + 200);

    device.ui.start.img_loading = lv_img_create(device.ui.scr);
    lv_img_set_src(device.ui.start.img_loading, "/img/dark/loading.png");
    lv_obj_align_to(device.ui.start.img_loading, device.ui.start.label, LV_ALIGN_OUT_RIGHT_MID, 10, 0);

    lv_anim_init(&device.ui.start.loading_am);
    lv_anim_set_var(&device.ui.start.loading_am, device.ui.start.img_loading);

    lv_anim_set_exec_cb(&device.ui.start.loading_am, set_img_angle_callback);
    lv_anim_set_values(&device.ui.start.loading_am, 0, 3600 - 1);
    lv_anim_set_repeat_count(&device.ui.start.loading_am, LV_ANIM_REPEAT_INFINITE);
    lv_anim_set_time(&device.ui.start.loading_am, 1500);
    lv_anim_start(&device.ui.start.loading_am);

    // lv_scr_load_anim(device.ui.start.scr, LV_SCR_LOAD_ANIM_FADE_ON, 1000, 0, true);
    lv_scr_load(device.ui.scr);

    ui->timer_1 = lv_timer_create(timer_callback_main, 2000 + lv_rand(0, 1000), NULL);
    lv_timer_set_repeat_count(ui->timer_1, 10);
}

void timer_callback_main(lv_timer_t *timer)
{
    static int count = 0;
    count++;
    if (count > 5 || device.cpl.program_count > 0)
    {
        lv_timer_del(timer);
        page_main();
    }
}

void set_img_angle_callback(void *obj, int32_t v)
{
    lv_img_set_angle((lv_obj_t *)obj, v);
}

/************************ (C) COPYRIGHT PURESUN *****END OF FILE***************/
